package com.wuhan.template.module.home.activity;

import android.content.Intent;
import android.graphics.Color;
import android.support.annotation.NonNull;
import android.support.design.widget.TabLayout;
import android.support.v4.app.Fragment;
import android.support.v4.view.ViewPager;
import android.view.View;
import android.widget.ImageView;

import com.wuhan.template.R;
import com.wuhan.template.base.BaseActivity;
import com.wuhan.template.module.home.adapter.BaoLiaoFragmentAdapter;
import com.wuhan.template.module.home.fragment.DaJiaBaoLiaoFragment;
import com.wuhan.template.module.home.fragment.ZiXunFragment;
import com.wuhan.template.utils.EventMessage;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import de.greenrobot.event.EventBus;

/**
 * Created by Administrator on 2016/5/11 0011.
 */
public class BaoLiaoActivity extends BaseActivity {

    @BindView(R.id.sliding_tab_baoliao)
    protected TabLayout tabLayout;

    @BindView(R.id.baoliao_viewPage)
    protected ViewPager viewPager;

    @BindView(R.id.baoliao_image)
    protected ImageView backImage;

    @Override
    protected int getLayoutId() {
        return R.layout.activity_baoliao;
    }

    private List<Fragment> fragments = new ArrayList<>();

    @Override
    protected void initViews() {

        Fragment fragment = DaJiaBaoLiaoFragment.newInstance("0");
        fragments.add(fragment);
        fragment = ZiXunFragment.newInstance();
        fragments.add(fragment);

        BaoLiaoFragmentAdapter fragmentAdapter =
                new BaoLiaoFragmentAdapter(getSupportFragmentManager(), fragments);
        viewPager.setAdapter(fragmentAdapter);

        tabLayout.setSelectedTabIndicatorColor(Color.BLUE);
        tabLayout.setTabMode(TabLayout.MODE_FIXED);
        tabLayout.setupWithViewPager(viewPager);

        //可有可无  无所谓
        viewPager.addOnPageChangeListener(
                new TabLayout.TabLayoutOnPageChangeListener(tabLayout));

        tabLayout.setOnTabSelectedListener(new TabLayout.OnTabSelectedListener() {
            @Override
            public void onTabSelected(TabLayout.Tab tab) {
                viewPager.setCurrentItem(tab.getPosition());
            }

            @Override
            public void onTabUnselected(TabLayout.Tab tab) {

            }

            @Override
            public void onTabReselected(TabLayout.Tab tab) {

            }
        });
        backImage.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(BaoLiaoActivity.this,MainActivity.class);
                startActivity(intent);
                finish();
            }
        });

    }

    @Override
    protected void loadData() {

    }

    @Override
    protected void postEventResult(@NonNull EventMessage message) {

    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        EventBus.getDefault().unregister(this);
    }


}
